import type { LockInfo } from '@/types/store'
import { defineStore } from 'pinia'

interface LockState {
  lockInfo: Nullable<LockInfo>
}

export const useLockStore = defineStore({
  id: 'app-lock',
  state: (): LockState => ({
    lockInfo: { pwd: '123456', isLock: false }
  }),
  getters: {
    getLockInfo(): LockInfo {
      return this.lockInfo as LockInfo
    }
  },
  actions: {
    resetLockInfo() {
      // Persistent.removeLocal(LOCK_INFO_KEY);
      this.lockInfo = null
    },
    // Unlock
    async unLock(password?: string) {
      // if (this.lockInfo?.pwd === password) {
      //   this.resetLockInfo();
      //   return true;
      // }
      // const tryLogin = async () => {
      //   try {
      //     const username = userStore.getUserInfo?.username;
      //     const res = await userStore.login({
      //       username,
      //       password: password!,
      //       goHome: false,
      //       mode: 'none',
      //     });
      //     if (res) {
      //       this.resetLockInfo();
      //     }
      //     return res;
      //   } catch (error) {
      //     return false;
      //   }
      // };
      // return await tryLogin();
    }
  }
})
